Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple appends of '_dg' in name attribute on calling inverse() #6563

Merged
merged 3 commits into from
Jun 12, 2021

Conversation

jwalaQ
Copy link
Contributor

@jwalaQ jwalaQ commented Jun 11, 2021

Summary
Each call to a gate's inverse method appends '_dg' to the name attribute of the gate.

Details and comments

Upon running the following code,

qc = QuantumCircuit(2)
qc.cx(0,1)
qc_gate = qc.to_gate(name='qc_gate')
qc_gate_inv = qc_gate.inverse()
qc_gate_inv_inv = qc_gate_inv.inverse()

print(qc_gate.name)
print(qc_gate_inv.name)
print(qc_gate_inv_inv.name)

The output was:

circuit_name
circuit_name_dg
circuit_name_dg_dg

The output after the proposed changes is:

circuit_name
circuit_name_dg
circuit_name

If inverse() method of Gate is called multiple times, each call appended
'_dg' to the end of the name attribute, i.e. 'gate_name_dg_dg'. This commit
fixes it by checking if the name already contains '_dg'. If so, the '_dg'
is removed from the name. If not, '_dg' is added.
@jwalaQ jwalaQ requested a review from a team as a code owner June 11, 2021 22:07
@ajavadia ajavadia merged commit 0df56b3 into Qiskit:main Jun 12, 2021
@jwalaQ jwalaQ deleted the fix-double-dg branch July 29, 2021 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants